<?php 
namespace app\index\controller;
class Wechat{
    /**
     * 微信token验证信息
     */
    public function verify(){
      	if(isset($_GET['echostr'])){
            $this->valid();
        }else{
            $this->responseMsg();
        }
    }
    
    private function valid(){
        $echoStr = $_GET["echostr"];
        if($this->checkSignature()){
            echo $echoStr;
            exit;
        }
    }
    
    private function checkSignature(){
        $wechatInfo = $this->getWechatInfo();
        $signature = $_GET["signature"];
        $timestamp = $_GET["timestamp"];
        $nonce = $_GET["nonce"];
        $token = $wechatInfo['token'];
        $tmpArr = array($token, $timestamp, $nonce);
        sort($tmpArr, SORT_STRING);
        $tmpStr = implode( $tmpArr );
        $tmpStr = sha1( $tmpStr );
        if( $tmpStr == $signature ){
            return true;
        }else{
            return false;
        }
    }
}